package net.lcheng.service.impl;

import net.lcheng.dao.UserBankcardMapper;
import net.lcheng.model.UserBankcard;
import net.lcheng.model.UserBankcardExample;
import net.lcheng.service.UserBankcardService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by zwr on 2016/7/9 0009.
 */
@Service
public class UserBankcardServiceImpl implements UserBankcardService {
  @Resource
  private UserBankcardMapper userBankcardMapper;
    @Override
    public int addBakcard(UserBankcard userBankcard) {

        return userBankcardMapper.insert(userBankcard);
    }

  @Override
  public int deleteBakcard(String bakcardId) {
    return userBankcardMapper.deleteByPrimaryKey(bakcardId);
  }


  @Override
  public UserBankcard getUserBankcardByUserId(String userId) {
    UserBankcardExample example=new UserBankcardExample();
    example.or().andUserIdEqualTo(userId);
    List<UserBankcard>list=userBankcardMapper.selectByExample(example);
    if (list!=null && list.size()>0){
      return list.get(0);
    }else
    return null;
  }

  @Override
  public UserBankcard getUserBankcardByBankcardId(String bankcardId) {
    return userBankcardMapper.selectByPrimaryKey(bankcardId);
  }

  @Override
  public List<UserBankcard> getBankcardByUserId(String userId) {
    UserBankcardExample example=new UserBankcardExample();
    example.or().andUserIdEqualTo(userId);
    return userBankcardMapper.selectByExample(example);
  }
}
